package com.flower.background.controller;

import com.flower.entity.Flower;
import com.flower.entity.FlowerDatas;
import com.flower.service.FlowerService;
import java.util.List;

import com.flower.utils.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
 * FlowerController 控制器类
 * @date 2019-03-11 16:38:26
 * @version 1.0
 */
@RestController
@RequestMapping("/flower")
public class FlowerController {

	@Autowired
	private FlowerService flowerService;

	/** 查询全部方法 */
	@GetMapping("/findAll")
	public List<Flower> findAll() {
		return flowerService.findAll();
	}

	/** 多条件分页查询方法 */
	@GetMapping("/findByPage")
	public PageResult findByPage(Flower flower, Integer page, Integer rows) {
		try {
			return flowerService.findByPage(flower, page, rows);
		}catch (Exception ex){
			ex.printStackTrace();
		}
		return null;
	}


	/** 添加方法 */
	@PostMapping("/save")
	public boolean save(@RequestBody FlowerDatas flowerDatas ) {
//		System.out.println(flowerDatas.getUrlList().size());
		try {
			flowerService.save(flowerDatas);
			return true;
		}catch (Exception ex){
			ex.printStackTrace();
		}
		return false;
	}

	/** 修改方法 */
	@PostMapping("/update")
	public boolean update(@RequestBody FlowerDatas flowerDatas ) {
		try {
			flowerService.update(flowerDatas);
			return true;
		}catch (Exception ex){
			ex.printStackTrace();
		}
		return false;
	}

	/** 删除方法 */
	@GetMapping("/delete")
	public boolean delete(Long[] ids) {
		try {
			flowerService.deleteAll(ids);
			return true;
		}catch (Exception ex){
			ex.printStackTrace();
		}
		return false;
	}


//	查询鲜花图片

	@GetMapping("/findByfid")
	public List<String>findImageByfId(Long fid){
		try {

			return  flowerService.findImageByFid(fid);

		}catch (Exception e){
			e.printStackTrace();
		}

		return  null;
	}


}
